package com.ziyun.pop.modules.storeMaterials.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ziyun.pop.modules.purchase.entity.StorePurchaseApplyDetailEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


/**
 * @Author ZhaoWei
 * @Date 2018/10/16 08:47
 * @Version V1.0
 */
public interface StorePurchaseApplyDetailDao extends BaseMapper<StorePurchaseApplyDetailEntity> {

	void saveStoreBFDatePur(@Param("map")Map<String,Object> map);

	int getStatusByApplyNo(@Param("applyNo")String applyNo);

	List<StorePurchaseApplyDetailEntity> getMaterialByinNo(@Param("inNo") String inNo);


	Integer updateStoreapply(@Param("map") Map<String,Object> map);

	@Select(" select spad.*,em.material_name AS materialName,em.specifications,em.width,em.length,em.weight,em.show_unit AS showUnit from store_purchase_apply_detail spad LEFT JOIN erp_material em ON spad.material_id = em.material_id WHERE spad.apply_no = #{applyNo} ")
	List<StorePurchaseApplyDetailEntity> getMaterialByApplyNo(@Param("applyNo") String applyNo);


	@Select(" select apply_id from store_purchase_apply where apply_no = #{applyNoNew} ")
	Integer getapplyId(@Param("applyNoNew") String applyNoNew);


	@Select(" select * from store_purchase_apply_detail where apply_no = #{applyNo} ")
	List<StorePurchaseApplyDetailEntity> selectApplyNo(@Param("applyNo") String applyNo);


	@Delete(" delete from store_purchase_apply_detail where apply_no = #{applyNo} and material_id = #{materialId} ")
	Integer deleteApplyNoAndMaterialId(@Param("applyNo") String applyNo,@Param("materialId") String materialId);

	@Select(" select receive_quantity from store_purchase_apply_detail where material_id = #{materialID} and apply_no = #{applyNO} ")
	BigDecimal getReceiveQuantity(@Param("applyNO") String applyNO,@Param("materialID") String materialID);


	@Select(" select material_quantity from store_purchase_apply_detail where material_id = #{materialID} and apply_no = #{applyNO} ")
	BigDecimal getMaterialQuantity(@Param("applyNO") String applyNO,@Param("materialID") String materialID);


	@Select(" select * from store_purchase_apply_detail where apply_no = #{applyNo} ")
	List<StorePurchaseApplyDetailEntity> getStorePurchaseApplyDetailByApplyNo(@Param("applyNo") String applyNo);


	@Update(" update store_purchase_apply_detail set receive_quantity = #{quantityRecive} where apply_no = #{applyNO} and material_id = #{materialID} ")
	Integer updateReceiveQuantity(@Param("quantityRecive") BigDecimal quantityRecive,@Param("applyNO") String applyNO,@Param("materialID") String materialID);


	@Select(" select total_money from store_purchase_apply where apply_no = #{inNo} ")
	BigDecimal getTotalMoney(@Param("inNo") String inNo);

	}


